package com.itbour.service.yjx.trade.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.common.util.StringUtils;
import com.itbour.dao.yjx.trade.YjxNotifyInfoDao;
import com.itbour.dto.tg.NotifyInfoDto;
import com.itbour.dto.yjx.trade.YjxNotifyInfoDto;
import com.itbour.service.yjx.trade.YjxNotifyInfoService;


/**
 * @author 李琦
 * 一键秀 消息通知管理
 */
public class YjxNotifyInfoServiceImpl implements YjxNotifyInfoService{
	private YjxNotifyInfoDao yjxNotifyInfoDao;
	
	
	public Page pageQueryStats(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		Page result = null;
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = yjxNotifyInfoDao.notifyInfoCnt(param);
		while(totalSize >0 && totalSize <= skipResults){
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}
		// 分页检索
		param.put("pageSize", pageSize);
		param.put("skipResults", skipResults);
		List<YjxNotifyInfoDto> data = yjxNotifyInfoDao.notifyInfo(param);
		result = new JspPage(skipResults, totalSize, pageSize, data);
		return result;
	}
	
	public List<YjxNotifyInfoDto> selectNotifyInfo(Map<String, Object> param) {
		return yjxNotifyInfoDao.selectNotifyInfo(param);
	}
	
	public void delTopic(String ids) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("ids", StringUtils.listToString2(StringUtils.stringToList2(ids)));
		yjxNotifyInfoDao.deleteNotifyInfoLogic(param);
	}
	
	
	
	public void updNotify(Map<String, Object> param) {//更新
		yjxNotifyInfoDao.updateNotifyInfoById(param);
	}
	
	// 新增 消息内容
	public void addNotify(YjxNotifyInfoDto notifyInfo) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("ntfy_type", notifyInfo.getNtfy_type());
		param.put("title", notifyInfo.getTitle());
		param.put("message", notifyInfo.getMessage());
		param.put("image", notifyInfo.getImage());
		param.put("url",  notifyInfo.getUrl());
		param.put("embed_url",  notifyInfo.getEmbed_url());
		param.put("width",  notifyInfo.getWidth());
		param.put("height",  notifyInfo.getHeight());
		param.put("disp_type",  notifyInfo.getDisp_type());
		param.put("encrypt",  notifyInfo.getEncrypt());
		param.put("start_time", notifyInfo.getStart_time());
		param.put("end_time", notifyInfo.getEnd_time());
		param.put("chk_freq", notifyInfo.getChk_freq());
		param.put("update_by", notifyInfo.getUpdate_by());
		yjxNotifyInfoDao.insertNotifyInfo(param);
	}
	
	public Page pageQueryNotifyEditMsg(Map<String, Object> param,
			Integer pageNo, Integer pageSize) {
		Page result = null;
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = yjxNotifyInfoDao.notifyEditMsgCnt(param);
		while(totalSize >0 && totalSize <= skipResults){
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}
		param.put("pageSize", pageSize);
		param.put("skipResults", skipResults);
		List<NotifyInfoDto> data = yjxNotifyInfoDao.notifyEditMsgInfo(param);
		result = new JspPage(skipResults, totalSize, pageSize, data);
		return result;
	}
	
	@Override
	public Page pageQueryNotifyUserMsg(Map<String, Object> param,
			Integer pageNo, Integer pageSize) {
		Page result = null;
		
		// 实际起始位置
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = yjxNotifyInfoDao.notifyEditUserCnt(param);
		
		while(totalSize >0 && totalSize <= skipResults){
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}
		
		// 分页检索
		param.put("pageSize", pageSize);
		param.put("skipResults", skipResults);
		List<NotifyInfoDto> data = yjxNotifyInfoDao.notifyEditUserInfo(param);

		result = new JspPage(skipResults, totalSize, pageSize, data);
		return result;
	}
	
	public void addNotifyMsg(NotifyInfoDto notifyInfo) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("notify_id", notifyInfo.getNotify_id());
		param.put("user_id", notifyInfo.getUser_id());
		param.put("update_by", notifyInfo.getUpdate_by());
		yjxNotifyInfoDao.insertNotifyMsg(param);
	}

	
	
	
	
	
	public YjxNotifyInfoDao getYjxNotifyInfoDao() {
		return yjxNotifyInfoDao;
	}
	public void setYjxNotifyInfoDao(YjxNotifyInfoDao yjxNotifyInfoDao) {
		this.yjxNotifyInfoDao = yjxNotifyInfoDao;
	}
}
